package ejb;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.NoResultException;
import javax.persistence.Query;

import dao.BaseDao;
import entity.Users;

@Stateless
public class UsersBean extends BaseDao<Users> implements UsersBeanRemote, UsersBeanLocal {

	@SuppressWarnings("unchecked")
	@Override
	public List<Users> getAll() {
		Query query = this.em.createNamedQuery("Users.findAll");
		return query.getResultList();
	}

	@Override
	public Users authenticate(String username, String password) {
		Query query = this.em.createNamedQuery("Users.findByUsernameAndPassword");
		query.setParameter("username", username);
		query.setParameter("password", password);
		try {
			return (Users) query.getSingleResult();
		} catch(NoResultException ex) {
			return null;
		}
	}

}
